﻿using Topthink.Ruitu.QuestionBank.Authors;
using Topthink.Ruitu.QuestionBank.Books;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;

namespace Topthink.Ruitu.QuestionBank.EntityFrameworkCore
{
    [ConnectionStringName("QuestionBank")]
    public class QuestionBankDbContext : AbpDbContext<QuestionBankDbContext>, IQuestionBankDbContext
    {
        public DbSet<Book> Books { get; set; }
        
        public DbSet<Author> Authors { get; set; }
        
        public static string TablePrefix { get; set; } = QuestionBankConsts.DefaultDbTablePrefix;

        public static string Schema { get; set; } = QuestionBankConsts.DefaultDbSchema;

        public QuestionBankDbContext(DbContextOptions<QuestionBankDbContext> options) 
            : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.ConfigureQuestionBank(options =>
            {
                options.TablePrefix = TablePrefix;
                options.Schema = Schema;
            });
        }
    }
}